package com.sxbbc.common.core.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.function.common.GetRest;
import com.function.common.RestResponse;
import com.sxbbc.common.basics.exceptions.ThrowJsonException;
import com.sxbbc.common.core.entity.jz.SysAgreement;
import com.sxbbc.common.core.mapper.jz.SysAgreementMapper;
import com.sxbbc.common.core.service.ISysAgreementService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 系统协议表 服务实现类
 * </p>
 *
 * @author leehao
 * @since 2019-04-28
 */
@Service
public class SysAgreementServiceImpl extends ServiceImpl<SysAgreementMapper, SysAgreement> implements ISysAgreementService {

    @Override
    public RestResponse editAgree(SysAgreement agree) {
        if (StringUtils.isBlank(agree.getTitle())) {
            return GetRest.getFail("请输入协议标题");
        }
        if (StringUtils.isBlank(agree.getContent())) {
            return GetRest.getFail("请输入协议内容");
        }
        boolean save = false;
        try {
            save = super.saveOrUpdate(agree);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (!save) {
            throw new ThrowJsonException("保存协议失败");
        }
        return GetRest.getSuccess("保存成功");
    }
}
